package com.yesido.javabase.paixu;

import java.util.Arrays;

/**
 * @author yesido
 * @description
 * @date 2023-07-05 17:46
 * @Version 8.3
 */
public class InsertPaixu  {

    public static void main(String[] args) {
        int[] nums = {38,65,76,97,13,27,49};
        int[] insert = getInsert(nums);
        System.out.println(Arrays.toString(insert));
    }
    public static int[] getInsert(int[] nums){
        //插入排序 从下标1开始
        for (int i = 1; i < nums.length; i++) {
            int j = i,temp = nums[i];
            if (nums[j-1]>temp){
                //开始移动
                while(j>=1 && nums[j-1]>temp){
                    nums[j] = nums[j-1];
                    j--;
                }
            }
            nums[j] = temp;
            System.out.println("第"+i+"趟排序结果："+Arrays.toString(nums));
        }
        return nums;
    }
}
